package br.ufpe.cin.mac.middleware.components.concrete.Security;

import java.util.Iterator;
import java.util.List;

import br.ufpe.cin.mac.middleware.components.ConcreteComponent;
import br.ufpe.cin.mac.util.Message;


/**
 * Class Security
 * 
 * @author Osmany
 * @author Rafael Roque
 *
 */
public class Security extends ConcreteComponent implements SecurityMBean{

	public Security(){
		super(Security.class.getCanonicalName());
	}
		
	
	
	/* ************************************************************ * 
	 * ********************	INTERNAL METHODS ********************** *     
	 * ************************************************************ */ 
	
	protected void msgManager(Message msg) {
		List<String> ops = msg.readOperations();
		Iterator<String> it = ops.iterator();
		while(it.hasNext()) {
			
			String op = (String) it.next();
			if(op.equals("sendResponse"))
				sendResponse(msg);
			
			else if (op.equals("sendRequest"));
				sendRequest(msg);
		}
	}
	
	private void sendResponse(Message msg){
		buffer.put(msg.hashCode(),msg);
		sendNotification(msg,"terP");
	}
	
	private void sendRequest(Message msg) {
		buffer.put(msg.hashCode(),msg);
		sendNotification(msg,"invU");
	}
}
